home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16892 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: surfnet.nl!sun4nl!ittpub!ittpub!nntp
  2. Newsgroups: comp.lang.c++
  3. Subject: Re: Why don't you use garbage collection
  4. Message-ID: <1996Apr12.170708.1835@ittpub>
  5. From: wil@ittpub.nl (Wil Evers)
  6. Date: 12 Apr 96 17:07:07 WET
  7. References: <316D291F.465D@sto.fdata.se>
  8. Distribution: world
  9. Nntp-Posting-Host: lintilla
  10.  
  11. In article <316D291F.465D@sto.fdata.se> Niklas Mellin  
  12. <niklas.mellin@sto.fdata.se> writes:
  13.  
  14. > No major C/C++ compiler includes a garbage collector, because it is not  
  15. > a part of the C++ language. If you want a garbage collector you should
  16. > go out looking for a class library that implements it, not for a
  17. > compiler. A C++ compiler that do garbage collection when you forget
  18. > delete wouldn't be a C++ compiler.
  19.   
  20. That depends on what you call garbage collection. If the garbage collector  
  21. would do a `delete' on an unreferenced object, it would not be conforming  
  22. because that would imply the object's destructor is called at a point in  
  23. time when the state of the program is unknown.
  24.  
  25. However, I don't think there is anything in the ISO C and C++ standards  
  26. that precludes a garbage collector from returning unreferenced objects to  
  27. the pool of free memory.
  28.  
  29. In my opinion, this subtle difference is why garbage collection would be  
  30. appropriate for C, but not for C++. C++ destructors are often used to  
  31. release other resources than memory. If C++ programmers would get sloppy  
  32. about deleting their heap objects ("don't worry about deleting it, the  
  33. collector will do it for you"), we might end up with too many open file  
  34. descriptors, eternal database locks, forever blocking semaphores and  
  35. expensive telephone bills.
  36.  
  37. - Wil
  38.